package com.event.service.impl;

import com.event.mapper.UserMapper;
import com.event.pojo.User;
import com.event.service.UserService;
import com.event.utils.Md5Util;
import com.event.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;

    @Override
    public User findByUserName(String userName) {
        return userMapper.findByUserName(userName);
    }

    @Override
    public void register(String userName, String password) {
        String md5String = Md5Util.getMD5String(password);
        userMapper.add(userName,md5String);

    }

    @Override
    public void update(User user) {
        userMapper.update(user);
    }

    @Override
    public void updateAvatar(String avatar) {
        Map<String,Object> map= ThreadLocalUtil.get();
        userMapper.updateAvatar(avatar,(Integer)map.get("id"));
    }

    @Override
    public void updatePwd(String new_pwd) {
        Map<String,Object> map= ThreadLocalUtil.get();
        userMapper.updatePwd(Md5Util.getMD5String(new_pwd),(Integer)map.get("id"));
    }
}
